# agents/factor_agents/hyacine_agent.py
from .base_factor_agent import BaseFactorAgent
from game_engine.game_state import FactorDevelopment, GameWorld
import numpy as np

class HyacineAgent(BaseFactorAgent):
    """风堇智能体 - 治疗辅助特化"""
    
    def __init__(self, factor: FactorDevelopment, game_world: GameWorld):
        super().__init__(factor, game_world)
        self.personality_traits.update({
            "aggression": 0.2,      # 低攻击性
            "social": 0.8,          # 高社交性
            "healing_priority": 0.7  # 治疗优先度
        })
        self.patients = []  # 正在治疗的队友
    
    def make_decision(self, current_time: int) -> str:
        """风堇的决策逻辑"""
        situation = self.evaluate_situation()
        
        # 优先治疗濒死队友
        critical_allies = situation["critical_allies"]
        if critical_allies:
            most_critical = min(critical_allies, key=lambda x: x.attributes['health'])
            self.patients.append(most_critical)
            if self.should_use_special_ability():
                return f"sky_healing:{most_critical.name}"
            else:
                return f"emergency_heal:{most_critical.name}"
        
        # 治疗受伤队友
        if situation["injured_allies"]:
            injured_ally = situation["injured_allies"][0]
            return f"standard_heal:{injured_ally.name}"
        
        # 增强队友
        if situation["healthy_allies"] and self.factor.special_charges > 0:
            return "buff_allies"
        
        # 自我提升
        return "train_healing"
    
    def evaluate_situation(self) -> Dict:
        """评估当前局势"""
        nearby_factors = self.get_nearby_factors(25.0)  # 风堇有更大的感知范围
        
        critical_allies = []
        injured_allies = []
        healthy_allies = []
        
        for factor in nearby_factors:
            health_ratio = factor.attributes['health'] / 100.0
            if health_ratio < 0.3:
                critical_allies.append(factor)
            elif health_ratio < 0.7:
                injured_allies.append(factor)
            else:
                healthy_allies.append(factor)
        
        return {
            "critical_allies": critical_allies,
            "injured_allies": injured_allies, 
            "healthy_allies": healthy_allies,
            "self_health": self.factor.attributes['health'],
            "nearby_threats": [f for f in nearby_factors if self._is_potential_threat(f)]
        }